//% color="#4169E1" iconWidth=50 iconHeight=40
namespace RainSensor{

    //% block="雨量计模块初始化 直到成功 I2C模式" blockType="command" 
    export function init(parameter: any, block: any) {

        Generator.addImport("from DFRobot_RainfallSensor import *");
        Generator.addCode(`rainSensor=DFRobot_RainfallSensor_I2C()
while (rainSensor.begin() == False):
    print("Sensor initialize failed!!")
    time.sleep(1)
rainSensor.set_rain_accumulated_value(0.2794)
print("version:"+str(rainSensor.get_firmware_version()))
`);
   
    }


    //% block="读取上电后累计雨量(mm)" blockType="reporter"
    export function get_rainfall(parameter: any, block: any) { 
        Generator.addCode( [`rainSensor.get_rainfall()`,Generator.ORDER_UNARY_POSTFIX]);
   
   }

    //% block="读取[HOUR]小时内累计雨量(mm)" blockType="reporter"
    //% HOUR.shadow="range"   HOUR.params.min=1    HOUR.params.max=24    HOUR.defl=1
    export function get_rainfall_time(parameter: any, block: any) { 
        let hour = parameter.HOUR.code;
        Generator.addCode( [`rainSensor.get_rainfall_time(${hour})`,Generator.ORDER_UNARY_POSTFIX]);
   
   }
/*
      //% block="读取雨量翻斗次数" blockType="reporter"
      export function get_raw_data(parameter: any, block: any) { 
        Generator.addCode( [`rainSensor.get_raw_data(3)`,Generator.ORDER_UNARY_POSTFIX]);
   
   } 
   */


}